﻿using RecruitStudents.Client.BLL;
using RecruitStudents.Utility;
using RecruitStudents.Utility.Helper;
using RecruitStudents.Utility.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RecruitStudents.Client.Base
{
    public partial class Base_ExamRoom_Option : BaseForm
    {
        TB_Exam_ExamRoom ExamRoomModel = null;
        ServiceBase service = new ServiceBase();
        string strEntretenimientohID = string.Empty;
        string strExamRoomID = string.Empty;
        public Base_ExamRoom_Option(string _EntretenimientohID, string _ExamRoomID)
        {
            InitializeComponent();
            strEntretenimientohID = _EntretenimientohID;
            strExamRoomID = _ExamRoomID;
            this.BindModel();
        }

        private void BindModel()
        {
            if (!string.IsNullOrEmpty(strExamRoomID))
            {
                ExamRoomModel = service.GetExamRoomModel(strExamRoomID);
                if (ExamRoomModel != null)
                {
                    //txtNo.Text = ExamRoomModel.ExamRoomNO;
                    //txtNo.Enabled = false;
                    txtName.Text = ExamRoomModel.ExamRoomName;
                    if (ExamRoomModel.IsActive == "1")
                    {
                        chkSFYX.Checked = true;
                    }
                    else
                    {
                        chkSFYX.Checked = false;
                    }
                }
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Close();
        }

        private void buttonX2_Click(object sender, EventArgs e)
        {
            try
            {
                if (ExamRoomModel == null)
                {
                    ExamRoomModel = new TB_Exam_ExamRoom();
                    //if (txtNo.Text.Length == 0)
                    //{
                    //    ExamRoomModel.ExamRoomNO = Guid.NewGuid().ToSafeString();
                    //}
                    //else
                    //{
                    //    ExamRoomModel.ExamRoomNO = txtNo.Text;
                    //}
                    ExamRoomModel.EntretenimientohID = strEntretenimientohID;
                }
                ExamRoomModel.ExamRoomName = txtName.Text;
                ExamRoomModel.ExamYear = SessionerHelper.SystemYear;
                ExamRoomModel.IsActive = chkSFYX.Checked ? "1" : "0";
                if (service.SaveExamRoom(ExamRoomModel))
                {
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                DevHelper.ShowErrorMessageBox("操作数据出现错误:" + ex.Message);
                DevHelper.HideWaiting();
            }
        }
    }
}
